#include <chrono>
#include <memory>
#include <string>

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

using namespace std::chrono_literals;

class ParamNode : public rclcpp::Node
{
   public:
    ParamNode() : Node("param_node")
    {
        // 声明参数
        this->declare_parameter("param_string", "default_value");
        this->declare_parameter("param_int", 42);
        this->declare_parameter("param_double", 3.14);
        this->declare_parameter("param_bool", true);

        // 创建定时器，定期打印参数值
        timer_ = this->create_wall_timer(3s, [this]() -> void {
            std::string param_string = this->get_parameter("param_string").as_string();
            int param_int = this->get_parameter("param_int").as_int();
            double param_double = this->get_parameter("param_double").as_double();
            bool param_bool = this->get_parameter("param_bool").as_bool();

            RCLCPP_INFO(this->get_logger(), "Parameters - String: %s, Int: %d, Double: %.2f, Bool: %s",
                        param_string.c_str(), param_int, param_double, param_bool ? "true" : "false");
        });

        RCLCPP_INFO(this->get_logger(), "Parameter node started");
    }

   private:
    rclcpp::TimerBase::SharedPtr timer_;
};

int main(int argc, char *argv[])
{
    rclcpp::init(argc, argv);
    rclcpp::spin(std::make_shared<ParamNode>());
    rclcpp::shutdown();
    return 0;
}
